from django.contrib import admin

from .models import  Activity, ActivityCategory, ActivityParticipation, DiscussionLike, \
    DiscussionComment, ActivityDiscussion, ReviewLike, ActivityReview


@admin.register(ActivityCategory)
class ActivityCategoryAdmin(admin.ModelAdmin):
    list_display = ('name',)


@admin.register(Activity)
class ActivityAdmin(admin.ModelAdmin):
    # 在列表页显示分类名称
    list_display = ['title', 'get_category_name', 'organizer', 'start_time', 'status', 'current_participants']
    list_filter = ['category', 'status', 'start_time']
    search_fields = ['title', 'description', 'location_name']
    readonly_fields = ['views', 'shares', 'current_participants']
    list_per_page = 20

    # 添加自定义方法显示分类名称
    def get_category_name(self, obj):
        return obj.category.name

    get_category_name.short_description = '分类名称'
    get_category_name.admin_order_field = 'category__name'

@admin.register(ActivityParticipation)
class ActivityParticipationAdmin(admin.ModelAdmin):
    pass

@admin.register(ActivityReview)
class ActivityReviewAdmin(admin.ModelAdmin):
    pass

@admin.register(ReviewLike)
class ReviewLikeAdmin(admin.ModelAdmin):
    pass

@admin.register(ActivityDiscussion)
class ActivityDiscussionAdmin(admin.ModelAdmin):
    pass

@admin.register(DiscussionComment)
class DiscussionCommentAdmin(admin.ModelAdmin):
    pass

@admin.register(DiscussionLike)
class DiscussionLikeAdmin(admin.ModelAdmin):
    pass